package com.yaozheng.vocationaltraining.service.impl.collect;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.collect.IMyCollectListView;
import com.yaozheng.vocationaltraining.service.collect.MyCollectListService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

import java.util.HashMap;

/**
 * 我的收藏列表
 */
@EBean
public class MyCollectListServiceImpl implements MyCollectListService {
    IMyCollectListView iMyCollectListView;

    @Override
    public void init(IMyCollectListView iMyCollectListView) {
        this.iMyCollectListView = iMyCollectListView;
    }

    @Background
    @Override
    public void getMyCollectList(int lastId) {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/user/favorites?type=1,2&offset=" + lastId,
                    iMyCollectListView.getToken(),
                    new OkHttpClientManager.IBaseViewCallback(new BaseView(iMyCollectListView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iMyCollectListView.myCollectListSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iMyCollectListView.myCollectListError(error);
                        }

                    }));
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iMyCollectListView.isResponseResult()) {
                iMyCollectListView
                        .myCollectListError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
